
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Javascript教程 - 对象的继承 - 小白AI.易名</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="Javascript教程"><meta name="keywords" content="小白AI.易名,xiaobaiai.net,Javascript,入门,教程,博客">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="小白AI.易名">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-page-footer-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="object.html" />
    
    
    <link rel="prev" href="this.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="apple-touch-icon" href='../../assets/images/apple-touch-icon.png'>
    
    
        
        <link rel="apple-touch-icon" sizes="120x120" href="../../assets/images/apple-touch-icon-120x120.png">
        
        <link rel="apple-touch-icon" sizes="180x180" href="../../assets/images/apple-touch-icon-180x180.png">
        
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../basic/">
            
                <a href="../basic/">
            
                    
                    入门篇
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../basic/introduction.html">
            
                <a href="../basic/introduction.html">
            
                    
                    导论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../basic/history.html">
            
                <a href="../basic/history.html">
            
                    
                    历史
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../basic/grammar.html">
            
                <a href="../basic/grammar.html">
            
                    
                    基本语法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../types/">
            
                <a href="../types/">
            
                    
                    数据类型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../types/general.html">
            
                <a href="../types/general.html">
            
                    
                    概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../types/null-undefined-boolean.html">
            
                <a href="../types/null-undefined-boolean.html">
            
                    
                    null,undefined和布尔值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../types/number.html">
            
                <a href="../types/number.html">
            
                    
                    数值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../types/string.html">
            
                <a href="../types/string.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../types/object.html">
            
                <a href="../types/object.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../types/function.html">
            
                <a href="../types/function.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../types/array.html">
            
                <a href="../types/array.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../operators/">
            
                <a href="../operators/">
            
                    
                    运算符
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../operators/arithmetic.html">
            
                <a href="../operators/arithmetic.html">
            
                    
                    算术运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../operators/comparison.html">
            
                <a href="../operators/comparison.html">
            
                    
                    比较运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../operators/boolean.html">
            
                <a href="../operators/boolean.html">
            
                    
                    布尔运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../operators/bit.html">
            
                <a href="../operators/bit.html">
            
                    
                    二进制位运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../operators/priority.html">
            
                <a href="../operators/priority.html">
            
                    
                    其他运算符，运算顺序
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../features/">
            
                <a href="../features/">
            
                    
                    语法专题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../features/conversion.html">
            
                <a href="../features/conversion.html">
            
                    
                    数据类型的转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../features/error.html">
            
                <a href="../features/error.html">
            
                    
                    错误处理机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../features/style.html">
            
                <a href="../features/style.html">
            
                    
                    编程风格
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../features/console.html">
            
                <a href="../features/console.html">
            
                    
                    console 对象与控制台
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../stdlib/">
            
                <a href="../stdlib/">
            
                    
                    标准库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../stdlib/object.html">
            
                <a href="../stdlib/object.html">
            
                    
                    Object 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../stdlib/attributes.html">
            
                <a href="../stdlib/attributes.html">
            
                    
                    属性描述对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../stdlib/array.html">
            
                <a href="../stdlib/array.html">
            
                    
                    Array 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../stdlib/wrapper.html">
            
                <a href="../stdlib/wrapper.html">
            
                    
                    包装对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../stdlib/boolean.html">
            
                <a href="../stdlib/boolean.html">
            
                    
                    Boolean 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../stdlib/number.html">
            
                <a href="../stdlib/number.html">
            
                    
                    Number 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../stdlib/string.html">
            
                <a href="../stdlib/string.html">
            
                    
                    String 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../stdlib/math.html">
            
                <a href="../stdlib/math.html">
            
                    
                    Math 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../stdlib/date.html">
            
                <a href="../stdlib/date.html">
            
                    
                    Date 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../stdlib/regexp.html">
            
                <a href="../stdlib/regexp.html">
            
                    
                    RegExp 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../stdlib/json.html">
            
                <a href="../stdlib/json.html">
            
                    
                    JSON 对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="./">
            
                <a href="./">
            
                    
                    面向对象编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="new.html">
            
                <a href="new.html">
            
                    
                    实例对象与 New 命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="this.html">
            
                <a href="this.html">
            
                    
                    this 关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7.3" data-path="prototype.html">
            
                <a href="prototype.html">
            
                    
                    对象的继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="object.html">
            
                <a href="object.html">
            
                    
                    Object 对象的相关方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="strict.html">
            
                <a href="strict.html">
            
                    
                    严格模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../async/">
            
                <a href="../async/">
            
                    
                    异步操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../async/general.html">
            
                <a href="../async/general.html">
            
                    
                    概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../async/timer.html">
            
                <a href="../async/timer.html">
            
                    
                    定时器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../async/promise.html">
            
                <a href="../async/promise.html">
            
                    
                    Promise 对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../dom/">
            
                <a href="../dom/">
            
                    
                    DOM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../dom/general.html">
            
                <a href="../dom/general.html">
            
                    
                    概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../dom/node.html">
            
                <a href="../dom/node.html">
            
                    
                    Node 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../dom/nodelist.html">
            
                <a href="../dom/nodelist.html">
            
                    
                    NodeList 接口，HTMLCollection 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../dom/parentnode.html">
            
                <a href="../dom/parentnode.html">
            
                    
                    ParentNode 接口，ChildNode 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../dom/document.html">
            
                <a href="../dom/document.html">
            
                    
                    Document 节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="../dom/element.html">
            
                <a href="../dom/element.html">
            
                    
                    Element 节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="../dom/attributes.html">
            
                <a href="../dom/attributes.html">
            
                    
                    属性的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.8" data-path="../dom/text.html">
            
                <a href="../dom/text.html">
            
                    
                    Text 节点和 DocumentFragment 节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.9" data-path="../dom/css.html">
            
                <a href="../dom/css.html">
            
                    
                    CSS 操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.10" data-path="../dom/mutationobserver.html">
            
                <a href="../dom/mutationobserver.html">
            
                    
                    Mutation Observer API
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../events/">
            
                <a href="../events/">
            
                    
                    事件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../events/eventtarget.html">
            
                <a href="../events/eventtarget.html">
            
                    
                    EventTarget 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../events/model.html">
            
                <a href="../events/model.html">
            
                    
                    事件模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../events/event.html">
            
                <a href="../events/event.html">
            
                    
                    Event 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../events/mouse.html">
            
                <a href="../events/mouse.html">
            
                    
                    鼠标事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../events/keyboard.html">
            
                <a href="../events/keyboard.html">
            
                    
                    键盘事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../events/progress.html">
            
                <a href="../events/progress.html">
            
                    
                    进度事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../events/form.html">
            
                <a href="../events/form.html">
            
                    
                    表单事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../events/touch.html">
            
                <a href="../events/touch.html">
            
                    
                    触摸事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../events/drag.html">
            
                <a href="../events/drag.html">
            
                    
                    拖拉事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.10" data-path="../events/common.html">
            
                <a href="../events/common.html">
            
                    
                    其他常见事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.11" data-path="../events/globaleventhandlers.html">
            
                <a href="../events/globaleventhandlers.html">
            
                    
                    GlobalEventHandlers 接口
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../bom/">
            
                <a href="../bom/">
            
                    
                    浏览器模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../bom/engine.html">
            
                <a href="../bom/engine.html">
            
                    
                    浏览器模型概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../bom/window.html">
            
                <a href="../bom/window.html">
            
                    
                    window 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../bom/navigator.html">
            
                <a href="../bom/navigator.html">
            
                    
                    Navigatror 对象，Screen 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../bom/cookie.html">
            
                <a href="../bom/cookie.html">
            
                    
                    Cookie
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../bom/xmlhttprequest.html">
            
                <a href="../bom/xmlhttprequest.html">
            
                    
                    XMLHttpRequest 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../bom/same-origin.html">
            
                <a href="../bom/same-origin.html">
            
                    
                    同源限制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../bom/cors.html">
            
                <a href="../bom/cors.html">
            
                    
                    CORS 通信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../bom/storage.html">
            
                <a href="../bom/storage.html">
            
                    
                    Storage 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../bom/history.html">
            
                <a href="../bom/history.html">
            
                    
                    History 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../bom/location.html">
            
                <a href="../bom/location.html">
            
                    
                    Location对象，URL对象，URLSearchParams 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.11" data-path="../bom/arraybuffer.html">
            
                <a href="../bom/arraybuffer.html">
            
                    
                    ArrayBuffer 对象，Blob对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.12" data-path="../bom/file.html">
            
                <a href="../bom/file.html">
            
                    
                    File 对象，FileList 对象，FileReader 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.13" data-path="../bom/form.html">
            
                <a href="../bom/form.html">
            
                    
                    表单，FormData 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.14" data-path="../bom/indexeddb.html">
            
                <a href="../bom/indexeddb.html">
            
                    
                    IndexedDB API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.15" data-path="../bom/webworker.html">
            
                <a href="../bom/webworker.html">
            
                    
                    web worker
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../elements/">
            
                <a href="../elements/">
            
                    
                    附录:网页元素接口
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../elements/a.html">
            
                <a href="../elements/a.html">
            
                    
                    a超链接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../elements/image.html">
            
                <a href="../elements/image.html">
            
                    
                    image图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../elements/form.html">
            
                <a href="../elements/form.html">
            
                    
                    form表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../elements/input.html">
            
                <a href="../elements/input.html">
            
                    
                    input文本框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../elements/button.html">
            
                <a href="../elements/button.html">
            
                    
                    button按钮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../elements/option.html">
            
                <a href="../elements/option.html">
            
                    
                    option选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.7" data-path="../elements/video.html">
            
                <a href="../elements/video.html">
            
                    
                    video,audio音视频
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="_blank" rel="nofollow" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >对象的继承</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5BF9;&#x8C61;&#x7684;&#x7EE7;&#x627F;">&#x5BF9;&#x8C61;&#x7684;&#x7EE7;&#x627F;</h1>
<p>&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7F16;&#x7A0B;&#x5F88;&#x91CD;&#x8981;&#x7684;&#x4E00;&#x4E2A;&#x65B9;&#x9762;&#xFF0C;&#x5C31;&#x662F;&#x5BF9;&#x8C61;&#x7684;&#x7EE7;&#x627F;&#x3002;A &#x5BF9;&#x8C61;&#x901A;&#x8FC7;&#x7EE7;&#x627F; B &#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x80FD;&#x76F4;&#x63A5;&#x62E5;&#x6709; B &#x5BF9;&#x8C61;&#x7684;&#x6240;&#x6709;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x3002;&#x8FD9;&#x5BF9;&#x4E8E;&#x4EE3;&#x7801;&#x7684;&#x590D;&#x7528;&#x662F;&#x975E;&#x5E38;&#x6709;&#x7528;&#x7684;&#x3002;</p>
<p>&#x5927;&#x90E8;&#x5206;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7684;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#xFF0C;&#x90FD;&#x662F;&#x901A;&#x8FC7;&#x201C;&#x7C7B;&#x201D;&#xFF08;class&#xFF09;&#x5B9E;&#x73B0;&#x5BF9;&#x8C61;&#x7684;&#x7EE7;&#x627F;&#x3002;&#x4F20;&#x7EDF;&#x4E0A;&#xFF0C;JavaScript &#x8BED;&#x8A00;&#x7684;&#x7EE7;&#x627F;&#x4E0D;&#x901A;&#x8FC7; class&#xFF0C;&#x800C;&#x662F;&#x901A;&#x8FC7;&#x201C;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x201D;&#xFF08;prototype&#xFF09;&#x5B9E;&#x73B0;&#xFF0C;&#x672C;&#x7AE0;&#x4ECB;&#x7ECD; JavaScript &#x7684;&#x539F;&#x578B;&#x94FE;&#x7EE7;&#x627F;&#x3002;</p>
<p>ES6 &#x5F15;&#x5165;&#x4E86; class &#x8BED;&#x6CD5;&#xFF0C;&#x57FA;&#x4E8E; class &#x7684;&#x7EE7;&#x627F;&#x4E0D;&#x5728;&#x8FD9;&#x4E2A;&#x6559;&#x7A0B;&#x4ECB;&#x7ECD;&#xFF0C;&#x8BF7;&#x53C2;&#x9605;&#x300A;ES6 &#x6807;&#x51C6;&#x5165;&#x95E8;&#x300B;&#x4E00;&#x4E66;&#x7684;&#x76F8;&#x5173;&#x7AE0;&#x8282;&#x3002;</p>
<h2 id="&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x6982;&#x8FF0;">&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x6982;&#x8FF0;</h2>
<h3 id="&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x7F3A;&#x70B9;">&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x7F3A;&#x70B9;</h3>
<p>JavaScript &#x901A;&#x8FC7;&#x6784;&#x9020;&#x51FD;&#x6570;&#x751F;&#x6210;&#x65B0;&#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x6B64;&#x6784;&#x9020;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x89C6;&#x4E3A;&#x5BF9;&#x8C61;&#x7684;&#x6A21;&#x677F;&#x3002;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x5728;&#x6784;&#x9020;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Cat</span> (<span class="hljs-params">name, color</span>) </span>{
  <span class="hljs-keyword">this</span>.name = name;
  <span class="hljs-keyword">this</span>.color = color;
}

<span class="hljs-keyword">var</span> cat1 = <span class="hljs-keyword">new</span> Cat(<span class="hljs-string">&apos;&#x5927;&#x6BDB;&apos;</span>, <span class="hljs-string">&apos;&#x767D;&#x8272;&apos;</span>);

cat1.name <span class="hljs-comment">// &apos;&#x5927;&#x6BDB;&apos;</span>
cat1.color <span class="hljs-comment">// &apos;&#x767D;&#x8272;&apos;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>Cat</code>&#x51FD;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5B9A;&#x4E49;&#x4E86;<code>name</code>&#x5C5E;&#x6027;&#x548C;<code>color</code>&#x5C5E;&#x6027;&#xFF0C;&#x6240;&#x6709;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF08;&#x4E0A;&#x4F8B;&#x662F;<code>cat1</code>&#xFF09;&#x90FD;&#x4F1A;&#x751F;&#x6210;&#x8FD9;&#x4E24;&#x4E2A;&#x5C5E;&#x6027;&#xFF0C;&#x5373;&#x8FD9;&#x4E24;&#x4E2A;&#x5C5E;&#x6027;&#x4F1A;&#x5B9A;&#x4E49;&#x5728;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x4E0A;&#x9762;&#x3002;</p>
<p>&#x901A;&#x8FC7;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E3A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;&#xFF0C;&#x867D;&#x7136;&#x5F88;&#x65B9;&#x4FBF;&#xFF0C;&#x4F46;&#x662F;&#x6709;&#x4E00;&#x4E2A;&#x7F3A;&#x70B9;&#x3002;&#x540C;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x591A;&#x4E2A;&#x5B9E;&#x4F8B;&#x4E4B;&#x95F4;&#xFF0C;&#x65E0;&#x6CD5;&#x5171;&#x4EAB;&#x5C5E;&#x6027;&#xFF0C;&#x4ECE;&#x800C;&#x9020;&#x6210;&#x5BF9;&#x7CFB;&#x7EDF;&#x8D44;&#x6E90;&#x7684;&#x6D6A;&#x8D39;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Cat</span>(<span class="hljs-params">name, color</span>) </span>{
  <span class="hljs-keyword">this</span>.name = name;
  <span class="hljs-keyword">this</span>.color = color;
  <span class="hljs-keyword">this</span>.meow = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x55B5;&#x55B5;&apos;</span>);
  };
}

<span class="hljs-keyword">var</span> cat1 = <span class="hljs-keyword">new</span> Cat(<span class="hljs-string">&apos;&#x5927;&#x6BDB;&apos;</span>, <span class="hljs-string">&apos;&#x767D;&#x8272;&apos;</span>);
<span class="hljs-keyword">var</span> cat2 = <span class="hljs-keyword">new</span> Cat(<span class="hljs-string">&apos;&#x4E8C;&#x6BDB;&apos;</span>, <span class="hljs-string">&apos;&#x9ED1;&#x8272;&apos;</span>);

cat1.meow === cat2.meow
<span class="hljs-comment">// false</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>cat1</code>&#x548C;<code>cat2</code>&#x662F;&#x540C;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x4E24;&#x4E2A;&#x5B9E;&#x4F8B;&#xFF0C;&#x5B83;&#x4EEC;&#x90FD;&#x5177;&#x6709;<code>meow</code>&#x65B9;&#x6CD5;&#x3002;&#x7531;&#x4E8E;<code>meow</code>&#x65B9;&#x6CD5;&#x662F;&#x751F;&#x6210;&#x5728;&#x6BCF;&#x4E2A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x4E0A;&#x9762;&#xFF0C;&#x6240;&#x4EE5;&#x4E24;&#x4E2A;&#x5B9E;&#x4F8B;&#x5C31;&#x751F;&#x6210;&#x4E86;&#x4E24;&#x6B21;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x6BCF;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#xFF0C;&#x5C31;&#x4F1A;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;<code>meow</code>&#x65B9;&#x6CD5;&#x3002;&#x8FD9;&#x65E2;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#xFF0C;&#x53C8;&#x6D6A;&#x8D39;&#x7CFB;&#x7EDF;&#x8D44;&#x6E90;&#xFF0C;&#x56E0;&#x4E3A;&#x6240;&#x6709;<code>meow</code>&#x65B9;&#x6CD5;&#x90FD;&#x662F;&#x540C;&#x6837;&#x7684;&#x884C;&#x4E3A;&#xFF0C;&#x5B8C;&#x5168;&#x5E94;&#x8BE5;&#x5171;&#x4EAB;&#x3002;</p>
<p>&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#xFF0C;&#x5C31;&#x662F; JavaScript &#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#xFF08;prototype&#xFF09;&#x3002;</p>
<h3 id="prototype-&#x5C5E;&#x6027;&#x7684;&#x4F5C;&#x7528;">prototype &#x5C5E;&#x6027;&#x7684;&#x4F5C;&#x7528;</h3>
<p>JavaScript &#x7EE7;&#x627F;&#x673A;&#x5236;&#x7684;&#x8BBE;&#x8BA1;&#x601D;&#x60F3;&#x5C31;&#x662F;&#xFF0C;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x6240;&#x6709;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#xFF0C;&#x90FD;&#x80FD;&#x88AB;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x5171;&#x4EAB;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x5982;&#x679C;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x5B9A;&#x4E49;&#x5728;&#x539F;&#x578B;&#x4E0A;&#xFF0C;&#x90A3;&#x4E48;&#x6240;&#x6709;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x5C31;&#x80FD;&#x5171;&#x4EAB;&#xFF0C;&#x4E0D;&#x4EC5;&#x8282;&#x7701;&#x4E86;&#x5185;&#x5B58;&#xFF0C;&#x8FD8;&#x4F53;&#x73B0;&#x4E86;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x4E4B;&#x95F4;&#x7684;&#x8054;&#x7CFB;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#xFF0C;&#x5148;&#x770B;&#x600E;&#x4E48;&#x4E3A;&#x5BF9;&#x8C61;&#x6307;&#x5B9A;&#x539F;&#x578B;&#x3002;JavaScript &#x89C4;&#x5B9A;&#xFF0C;&#x6BCF;&#x4E2A;&#x51FD;&#x6570;&#x90FD;&#x6709;&#x4E00;&#x4E2A;<code>prototype</code>&#x5C5E;&#x6027;&#xFF0C;&#x6307;&#x5411;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-keyword">typeof</span> f.prototype <span class="hljs-comment">// &quot;object&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x9ED8;&#x8BA4;&#x5177;&#x6709;<code>prototype</code>&#x5C5E;&#x6027;&#xFF0C;&#x6307;&#x5411;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x666E;&#x901A;&#x51FD;&#x6570;&#x6765;&#x8BF4;&#xFF0C;&#x8BE5;&#x5C5E;&#x6027;&#x57FA;&#x672C;&#x65E0;&#x7528;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x5BF9;&#x4E8E;&#x6784;&#x9020;&#x51FD;&#x6570;&#x6765;&#x8BF4;&#xFF0C;&#x751F;&#x6210;&#x5B9E;&#x4F8B;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8BE5;&#x5C5E;&#x6027;&#x4F1A;&#x81EA;&#x52A8;&#x6210;&#x4E3A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Animal</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">this</span>.name = name;
}
Animal.prototype.color = <span class="hljs-string">&apos;white&apos;</span>;

<span class="hljs-keyword">var</span> cat1 = <span class="hljs-keyword">new</span> Animal(<span class="hljs-string">&apos;&#x5927;&#x6BDB;&apos;</span>);
<span class="hljs-keyword">var</span> cat2 = <span class="hljs-keyword">new</span> Animal(<span class="hljs-string">&apos;&#x4E8C;&#x6BDB;&apos;</span>);

cat1.color <span class="hljs-comment">// &apos;white&apos;</span>
cat2.color <span class="hljs-comment">// &apos;white&apos;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x6784;&#x9020;&#x51FD;&#x6570;<code>Animal</code>&#x7684;<code>prototype</code>&#x5C5E;&#x6027;&#xFF0C;&#x5C31;&#x662F;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;<code>cat1</code>&#x548C;<code>cat2</code>&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x3002;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E0A;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;<code>color</code>&#x5C5E;&#x6027;&#xFF0C;&#x7ED3;&#x679C;&#xFF0C;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x90FD;&#x5171;&#x4EAB;&#x4E86;&#x8BE5;&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x4E0D;&#x662F;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x81EA;&#x8EAB;&#x7684;&#x5C5E;&#x6027;&#x3002;&#x53EA;&#x8981;&#x4FEE;&#x6539;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#xFF0C;&#x53D8;&#x52A8;&#x5C31;&#x7ACB;&#x523B;&#x4F1A;&#x4F53;&#x73B0;&#x5728;<strong>&#x6240;&#x6709;</strong>&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x4E0A;&#x3002;</p>
<pre><code class="lang-javascript">Animal.prototype.color = <span class="hljs-string">&apos;yellow&apos;</span>;

cat1.color <span class="hljs-comment">// &quot;yellow&quot;</span>
cat2.color <span class="hljs-comment">// &quot;yellow&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;<code>color</code>&#x5C5E;&#x6027;&#x7684;&#x503C;&#x53D8;&#x4E3A;<code>yellow</code>&#xFF0C;&#x4E24;&#x4E2A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7684;<code>color</code>&#x5C5E;&#x6027;&#x7ACB;&#x523B;&#x8DDF;&#x7740;&#x53D8;&#x4E86;&#x3002;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x5176;&#x5B9E;&#x6CA1;&#x6709;<code>color</code>&#x5C5E;&#x6027;&#xFF0C;&#x90FD;&#x662F;&#x8BFB;&#x53D6;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;<code>color</code>&#x5C5E;&#x6027;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x5F53;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x672C;&#x8EAB;&#x6CA1;&#x6709;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#x6216;&#x65B9;&#x6CD5;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5B83;&#x4F1A;&#x5230;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x53BB;&#x5BFB;&#x627E;&#x8BE5;&#x5C5E;&#x6027;&#x6216;&#x65B9;&#x6CD5;&#x3002;&#x8FD9;&#x5C31;&#x662F;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x7279;&#x6B8A;&#x4E4B;&#x5904;&#x3002;</p>
<p>&#x5982;&#x679C;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x81EA;&#x8EAB;&#x5C31;&#x6709;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#x6216;&#x65B9;&#x6CD5;&#xFF0C;&#x5B83;&#x5C31;&#x4E0D;&#x4F1A;&#x518D;&#x53BB;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x5BFB;&#x627E;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x6216;&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript">cat1.color = <span class="hljs-string">&apos;black&apos;</span>;

cat1.color <span class="hljs-comment">// &apos;black&apos;</span>
cat2.color <span class="hljs-comment">// &apos;yellow&apos;</span>
Animal.prototype.color <span class="hljs-comment">// &apos;yellow&apos;;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;<code>cat1</code>&#x7684;<code>color</code>&#x5C5E;&#x6027;&#x6539;&#x4E3A;<code>black</code>&#xFF0C;&#x5C31;&#x4F7F;&#x5F97;&#x5B83;&#x4E0D;&#x518D;&#x53BB;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x8BFB;&#x53D6;<code>color</code>&#x5C5E;&#x6027;&#xFF0C;&#x540E;&#x8005;&#x7684;&#x503C;&#x4F9D;&#x7136;&#x4E3A;<code>yellow</code>&#x3002;</p>
<p>&#x603B;&#x7ED3;&#x4E00;&#x4E0B;&#xFF0C;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x4F5C;&#x7528;&#xFF0C;&#x5C31;&#x662F;&#x5B9A;&#x4E49;&#x6240;&#x6709;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x5171;&#x4EAB;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x3002;&#x8FD9;&#x4E5F;&#x662F;&#x5B83;&#x88AB;&#x79F0;&#x4E3A;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x56E0;&#xFF0C;&#x800C;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x89C6;&#x4F5C;&#x4ECE;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x884D;&#x751F;&#x51FA;&#x6765;&#x7684;&#x5B50;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript">Animal.prototype.walk = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.name + <span class="hljs-string">&apos; is walking&apos;</span>);
};
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>Animal.prototype</code>&#x5BF9;&#x8C61;&#x4E0A;&#x9762;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;<code>walk</code>&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x5C06;&#x53EF;&#x4EE5;&#x5728;&#x6240;&#x6709;<code>Animal</code>&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x4E0A;&#x9762;&#x8C03;&#x7528;&#x3002;</p>
<h3 id="&#x539F;&#x578B;&#x94FE;">&#x539F;&#x578B;&#x94FE;</h3>
<p>JavaScript &#x89C4;&#x5B9A;&#xFF0C;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x90FD;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#xFF08;prototype&#xFF09;&#x3002;&#x4E00;&#x65B9;&#x9762;&#xFF0C;&#x4EFB;&#x4F55;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x90FD;&#x53EF;&#x4EE5;&#x5145;&#x5F53;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#xFF1B;&#x53E6;&#x4E00;&#x65B9;&#x9762;&#xFF0C;&#x7531;&#x4E8E;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E5F;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;&#x6240;&#x4EE5;&#x5B83;&#x4E5F;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x539F;&#x578B;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5C31;&#x4F1A;&#x5F62;&#x6210;&#x4E00;&#x4E2A;&#x201C;&#x539F;&#x578B;&#x94FE;&#x201D;&#xFF08;prototype chain&#xFF09;&#xFF1A;&#x5BF9;&#x8C61;&#x5230;&#x539F;&#x578B;&#xFF0C;&#x518D;&#x5230;&#x539F;&#x578B;&#x7684;&#x539F;&#x578B;&#x2026;&#x2026;</p>
<p>&#x5982;&#x679C;&#x4E00;&#x5C42;&#x5C42;&#x5730;&#x4E0A;&#x6EAF;&#xFF0C;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x6700;&#x7EC8;&#x90FD;&#x53EF;&#x4EE5;&#x4E0A;&#x6EAF;&#x5230;<code>Object.prototype</code>&#xFF0C;&#x5373;<code>Object</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;<code>prototype</code>&#x5C5E;&#x6027;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x90FD;&#x7EE7;&#x627F;&#x4E86;<code>Object.prototype</code>&#x7684;&#x5C5E;&#x6027;&#x3002;&#x8FD9;&#x5C31;&#x662F;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x90FD;&#x6709;<code>valueOf</code>&#x548C;<code>toString</code>&#x65B9;&#x6CD5;&#x7684;&#x539F;&#x56E0;&#xFF0C;&#x56E0;&#x4E3A;&#x8FD9;&#x662F;&#x4ECE;<code>Object.prototype</code>&#x7EE7;&#x627F;&#x7684;&#x3002;</p>
<p>&#x90A3;&#x4E48;&#xFF0C;<code>Object.prototype</code>&#x5BF9;&#x8C61;&#x6709;&#x6CA1;&#x6709;&#x5B83;&#x7684;&#x539F;&#x578B;&#x5462;&#xFF1F;&#x56DE;&#x7B54;&#x662F;<code>Object.prototype</code>&#x7684;&#x539F;&#x578B;&#x662F;<code>null</code>&#x3002;<code>null</code>&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#xFF0C;&#x4E5F;&#x6CA1;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x539F;&#x578B;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x539F;&#x578B;&#x94FE;&#x7684;&#x5C3D;&#x5934;&#x5C31;&#x662F;<code>null</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">Object</span>.getPrototypeOf(<span class="hljs-built_in">Object</span>.prototype)
<span class="hljs-comment">// null</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8868;&#x793A;&#xFF0C;<code>Object.prototype</code>&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x662F;<code>null</code>&#xFF0C;&#x7531;&#x4E8E;<code>null</code>&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5C5E;&#x6027;&#xFF0C;&#x6240;&#x4EE5;&#x539F;&#x578B;&#x94FE;&#x5230;&#x6B64;&#x4E3A;&#x6B62;&#x3002;<code>Object.getPrototypeOf</code>&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x53C2;&#x6570;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#xFF0C;&#x5177;&#x4F53;&#x4ECB;&#x7ECD;&#x8BF7;&#x770B;&#x540E;&#x6587;&#x3002;</p>
<p>&#x8BFB;&#x53D6;&#x5BF9;&#x8C61;&#x7684;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#x65F6;&#xFF0C;JavaScript &#x5F15;&#x64CE;&#x5148;&#x5BFB;&#x627E;&#x5BF9;&#x8C61;&#x672C;&#x8EAB;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x5982;&#x679C;&#x627E;&#x4E0D;&#x5230;&#xFF0C;&#x5C31;&#x5230;&#x5B83;&#x7684;&#x539F;&#x578B;&#x53BB;&#x627E;&#xFF0C;&#x5982;&#x679C;&#x8FD8;&#x662F;&#x627E;&#x4E0D;&#x5230;&#xFF0C;&#x5C31;&#x5230;&#x539F;&#x578B;&#x7684;&#x539F;&#x578B;&#x53BB;&#x627E;&#x3002;&#x5982;&#x679C;&#x76F4;&#x5230;&#x6700;&#x9876;&#x5C42;&#x7684;<code>Object.prototype</code>&#x8FD8;&#x662F;&#x627E;&#x4E0D;&#x5230;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;<code>undefined</code>&#x3002;&#x5982;&#x679C;&#x5BF9;&#x8C61;&#x81EA;&#x8EAB;&#x548C;&#x5B83;&#x7684;&#x539F;&#x578B;&#xFF0C;&#x90FD;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x540C;&#x540D;&#x5C5E;&#x6027;&#xFF0C;&#x90A3;&#x4E48;&#x4F18;&#x5148;&#x8BFB;&#x53D6;&#x5BF9;&#x8C61;&#x81EA;&#x8EAB;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x8FD9;&#x53EB;&#x505A;&#x201C;&#x8986;&#x76D6;&#x201D;&#xFF08;overriding&#xFF09;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x4E00;&#x7EA7;&#x7EA7;&#x5411;&#x4E0A;&#xFF0C;&#x5728;&#x6574;&#x4E2A;&#x539F;&#x578B;&#x94FE;&#x4E0A;&#x5BFB;&#x627E;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#xFF0C;&#x5BF9;&#x6027;&#x80FD;&#x662F;&#x6709;&#x5F71;&#x54CD;&#x7684;&#x3002;&#x6240;&#x5BFB;&#x627E;&#x7684;&#x5C5E;&#x6027;&#x5728;&#x8D8A;&#x4E0A;&#x5C42;&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#xFF0C;&#x5BF9;&#x6027;&#x80FD;&#x7684;&#x5F71;&#x54CD;&#x8D8A;&#x5927;&#x3002;&#x5982;&#x679C;&#x5BFB;&#x627E;&#x67D0;&#x4E2A;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x5C06;&#x4F1A;&#x904D;&#x5386;&#x6574;&#x4E2A;&#x539F;&#x578B;&#x94FE;&#x3002;</p>
<p>&#x4E3E;&#x4F8B;&#x6765;&#x8BF4;&#xFF0C;&#x5982;&#x679C;&#x8BA9;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;<code>prototype</code>&#x5C5E;&#x6027;&#x6307;&#x5411;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x5C31;&#x610F;&#x5473;&#x7740;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x8C03;&#x7528;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> MyArray = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{};

MyArray.prototype = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>();
MyArray.prototype.constructor = MyArray;

<span class="hljs-keyword">var</span> mine = <span class="hljs-keyword">new</span> MyArray();
mine.push(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>);
mine.length <span class="hljs-comment">// 3</span>
mine <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Array</span> <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>mine</code>&#x662F;&#x6784;&#x9020;&#x51FD;&#x6570;<code>MyArray</code>&#x7684;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x7531;&#x4E8E;<code>MyArray.prototype</code>&#x6307;&#x5411;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x5B9E;&#x4F8B;&#xFF0C;&#x4F7F;&#x5F97;<code>mine</code>&#x53EF;&#x4EE5;&#x8C03;&#x7528;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#xFF08;&#x8FD9;&#x4E9B;&#x65B9;&#x6CD5;&#x5B9A;&#x4E49;&#x5728;&#x6570;&#x7EC4;&#x5B9E;&#x4F8B;&#x7684;<code>prototype</code>&#x5BF9;&#x8C61;&#x4E0A;&#x9762;&#xFF09;&#x3002;&#x6700;&#x540E;&#x90A3;&#x884C;<code>instanceof</code>&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x7528;&#x6765;&#x6BD4;&#x8F83;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x4E3A;&#x67D0;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x7ED3;&#x679C;&#x5C31;&#x662F;&#x8BC1;&#x660E;<code>mine</code>&#x4E3A;<code>Array</code>&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;<code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x8BE6;&#x7EC6;&#x89E3;&#x91CA;&#x8BE6;&#x89C1;&#x540E;&#x6587;&#x3002;</p>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8FD8;&#x51FA;&#x73B0;&#x4E86;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;<code>constructor</code>&#x5C5E;&#x6027;&#xFF0C;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x7684;&#x542B;&#x4E49;&#x4E0B;&#x4E00;&#x8282;&#x5C31;&#x6765;&#x89E3;&#x91CA;&#x3002;</p>
<h3 id="constructor-&#x5C5E;&#x6027;">constructor &#x5C5E;&#x6027;</h3>
<p><code>prototype</code>&#x5BF9;&#x8C61;&#x6709;&#x4E00;&#x4E2A;<code>constructor</code>&#x5C5E;&#x6027;&#xFF0C;&#x9ED8;&#x8BA4;&#x6307;&#x5411;<code>prototype</code>&#x5BF9;&#x8C61;&#x6240;&#x5728;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">P</span>(<span class="hljs-params"></span>) </span>{}
P.prototype.constructor === P <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x7531;&#x4E8E;<code>constructor</code>&#x5C5E;&#x6027;&#x5B9A;&#x4E49;&#x5728;<code>prototype</code>&#x5BF9;&#x8C61;&#x4E0A;&#x9762;&#xFF0C;&#x610F;&#x5473;&#x7740;&#x53EF;&#x4EE5;&#x88AB;&#x6240;&#x6709;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7EE7;&#x627F;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">P</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-keyword">var</span> p = <span class="hljs-keyword">new</span> P();

p.constructor === P <span class="hljs-comment">// true</span>
p.constructor === P.prototype.constructor <span class="hljs-comment">// true</span>
p.hasOwnProperty(<span class="hljs-string">&apos;constructor&apos;</span>) <span class="hljs-comment">// false</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>p</code>&#x662F;&#x6784;&#x9020;&#x51FD;&#x6570;<code>P</code>&#x7684;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x4F46;&#x662F;<code>p</code>&#x81EA;&#x8EAB;&#x6CA1;&#x6709;<code>constructor</code>&#x5C5E;&#x6027;&#xFF0C;&#x8BE5;&#x5C5E;&#x6027;&#x5176;&#x5B9E;&#x662F;&#x8BFB;&#x53D6;&#x539F;&#x578B;&#x94FE;&#x4E0A;&#x9762;&#x7684;<code>P.prototype.constructor</code>&#x5C5E;&#x6027;&#x3002;</p>
<p><code>constructor</code>&#x5C5E;&#x6027;&#x7684;&#x4F5C;&#x7528;&#x662F;&#xFF0C;&#x53EF;&#x4EE5;&#x5F97;&#x77E5;&#x67D0;&#x4E2A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x5230;&#x5E95;&#x662F;&#x54EA;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4EA7;&#x751F;&#x7684;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">F</span>(<span class="hljs-params"></span>) </span>{};
<span class="hljs-keyword">var</span> f = <span class="hljs-keyword">new</span> F();

f.constructor === F <span class="hljs-comment">// true</span>
f.constructor === <span class="hljs-built_in">RegExp</span> <span class="hljs-comment">// false</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>constructor</code>&#x5C5E;&#x6027;&#x786E;&#x5B9A;&#x4E86;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;<code>f</code>&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x662F;<code>F</code>&#xFF0C;&#x800C;&#x4E0D;&#x662F;<code>RegExp</code>&#x3002;</p>
<p>&#x53E6;&#x4E00;&#x65B9;&#x9762;&#xFF0C;&#x6709;&#x4E86;<code>constructor</code>&#x5C5E;&#x6027;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x4ECE;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x65B0;&#x5EFA;&#x53E6;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Constr</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-keyword">var</span> x = <span class="hljs-keyword">new</span> Constr();

<span class="hljs-keyword">var</span> y = <span class="hljs-keyword">new</span> x.constructor();
y <span class="hljs-keyword">instanceof</span> Constr <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>x</code>&#x662F;&#x6784;&#x9020;&#x51FD;&#x6570;<code>Constr</code>&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x53EF;&#x4EE5;&#x4ECE;<code>x.constructor</code>&#x95F4;&#x63A5;&#x8C03;&#x7528;&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;&#x8FD9;&#x4F7F;&#x5F97;&#x5728;&#x5B9E;&#x4F8B;&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x8C03;&#x7528;&#x81EA;&#x8EAB;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x6210;&#x4E3A;&#x53EF;&#x80FD;&#x3002;</p>
<pre><code class="lang-javascript">Constr.prototype.createCopy = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-keyword">this</span>.constructor();
};
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>createCopy</code>&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x65B0;&#x5EFA;&#x53E6;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x3002;</p>
<p><code>constructor</code>&#x5C5E;&#x6027;&#x8868;&#x793A;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E0E;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E4B;&#x95F4;&#x7684;&#x5173;&#x8054;&#x5173;&#x7CFB;&#xFF0C;&#x5982;&#x679C;&#x4FEE;&#x6539;&#x4E86;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#xFF0C;&#x4E00;&#x822C;&#x4F1A;&#x540C;&#x65F6;&#x4FEE;&#x6539;<code>constructor</code>&#x5C5E;&#x6027;&#xFF0C;&#x9632;&#x6B62;&#x5F15;&#x7528;&#x7684;&#x65F6;&#x5019;&#x51FA;&#x9519;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">this</span>.name = name;
}

Person.prototype.constructor === Person <span class="hljs-comment">// true</span>

Person.prototype = {
  method: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{}
};

Person.prototype.constructor === Person <span class="hljs-comment">// false</span>
Person.prototype.constructor === <span class="hljs-built_in">Object</span> <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x6784;&#x9020;&#x51FD;&#x6570;<code>Person</code>&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x6539;&#x6389;&#x4E86;&#xFF0C;&#x4F46;&#x662F;&#x6CA1;&#x6709;&#x4FEE;&#x6539;<code>constructor</code>&#x5C5E;&#x6027;&#xFF0C;&#x5BFC;&#x81F4;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x4E0D;&#x518D;&#x6307;&#x5411;<code>Person</code>&#x3002;&#x7531;&#x4E8E;<code>Person</code>&#x7684;&#x65B0;&#x539F;&#x578B;&#x662F;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x666E;&#x901A;&#x5BF9;&#x8C61;&#x7684;<code>constructor</code>&#x5C5E;&#x6027;&#x6307;&#x5411;<code>Object</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x5BFC;&#x81F4;<code>Person.prototype.constructor</code>&#x53D8;&#x6210;&#x4E86;<code>Object</code>&#x3002;</p>
<p>&#x6240;&#x4EE5;&#xFF0C;&#x4FEE;&#x6539;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x4E00;&#x822C;&#x8981;&#x540C;&#x65F6;&#x4FEE;&#x6539;<code>constructor</code>&#x5C5E;&#x6027;&#x7684;&#x6307;&#x5411;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x574F;&#x7684;&#x5199;&#x6CD5;</span>
C.prototype = {
  method1: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">...</span>) </span>{ ... },
  <span class="hljs-comment">// ...</span>
};

<span class="hljs-comment">// &#x597D;&#x7684;&#x5199;&#x6CD5;</span>
C.prototype = {
  <span class="hljs-keyword">constructor</span>: C,
  method1: function (...) { ... },
  <span class="hljs-comment">// ...</span>
};

<span class="hljs-comment">// &#x66F4;&#x597D;&#x7684;&#x5199;&#x6CD5;</span>
C.prototype.method1 = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">...</span>) </span>{ ... };
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x8981;&#x4E48;&#x5C06;<code>constructor</code>&#x5C5E;&#x6027;&#x91CD;&#x65B0;&#x6307;&#x5411;&#x539F;&#x6765;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x8981;&#x4E48;&#x53EA;&#x5728;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E0A;&#x6DFB;&#x52A0;&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x4FDD;&#x8BC1;<code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#x4E0D;&#x4F1A;&#x5931;&#x771F;&#x3002;</p>
<p>&#x5982;&#x679C;&#x4E0D;&#x80FD;&#x786E;&#x5B9A;<code>constructor</code>&#x5C5E;&#x6027;&#x662F;&#x4EC0;&#x4E48;&#x51FD;&#x6570;&#xFF0C;&#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x529E;&#x6CD5;&#xFF1A;&#x901A;&#x8FC7;<code>name</code>&#x5C5E;&#x6027;&#xFF0C;&#x4ECE;&#x5B9E;&#x4F8B;&#x5F97;&#x5230;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x540D;&#x79F0;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Foo</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-keyword">var</span> f = <span class="hljs-keyword">new</span> Foo();
f.constructor.name <span class="hljs-comment">// &quot;Foo&quot;</span>
</code></pre>
<h2 id="instanceof-&#x8FD0;&#x7B97;&#x7B26;">instanceof &#x8FD0;&#x7B97;&#x7B26;</h2>
<p><code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x8868;&#x793A;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x4E3A;&#x67D0;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x5B9E;&#x4F8B;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> v = <span class="hljs-keyword">new</span> Vehicle();
v <span class="hljs-keyword">instanceof</span> Vehicle <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5BF9;&#x8C61;<code>v</code>&#x662F;&#x6784;&#x9020;&#x51FD;&#x6570;<code>Vehicle</code>&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x6240;&#x4EE5;&#x8FD4;&#x56DE;<code>true</code>&#x3002;</p>
<p><code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x5DE6;&#x8FB9;&#x662F;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x53F3;&#x8FB9;&#x662F;&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;&#x5B83;&#x4F1A;&#x68C0;&#x67E5;&#x53F3;&#x8FB9;&#x6784;&#x5EFA;&#x51FD;&#x6570;&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#xFF08;prototype&#xFF09;&#xFF0C;&#x662F;&#x5426;&#x5728;&#x5DE6;&#x8FB9;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x94FE;&#x4E0A;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x4E0B;&#x9762;&#x4E24;&#x79CD;&#x5199;&#x6CD5;&#x662F;&#x7B49;&#x4EF7;&#x7684;&#x3002;</p>
<pre><code class="lang-javascript">v <span class="hljs-keyword">instanceof</span> Vehicle
<span class="hljs-comment">// &#x7B49;&#x540C;&#x4E8E;</span>
Vehicle.prototype.isPrototypeOf(v)
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>Object.prototype.isPrototypeOf</code>&#x7684;&#x8BE6;&#x7EC6;&#x89E3;&#x91CA;&#x89C1;&#x540E;&#x6587;&#x3002;</p>
<p>&#x7531;&#x4E8E;<code>instanceof</code>&#x68C0;&#x67E5;&#x6574;&#x4E2A;&#x539F;&#x578B;&#x94FE;&#xFF0C;&#x56E0;&#x6B64;&#x540C;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x5BF9;&#x591A;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x90FD;&#x8FD4;&#x56DE;<code>true</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> d = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>();
d <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Date</span> <span class="hljs-comment">// true</span>
d <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span> <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>d</code>&#x540C;&#x65F6;&#x662F;<code>Date</code>&#x548C;<code>Object</code>&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x56E0;&#x6B64;&#x5BF9;&#x8FD9;&#x4E24;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x90FD;&#x8FD4;&#x56DE;<code>true</code>&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x4EFB;&#x610F;&#x5BF9;&#x8C61;&#xFF08;&#x9664;&#x4E86;<code>null</code>&#xFF09;&#x90FD;&#x662F;<code>Object</code>&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x6240;&#x4EE5;<code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#x53EF;&#x4EE5;&#x5224;&#x65AD;&#x4E00;&#x4E2A;&#x503C;&#x662F;&#x5426;&#x4E3A;&#x975E;<code>null</code>&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = { foo: <span class="hljs-number">123</span> };
obj <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span> <span class="hljs-comment">// true</span>

<span class="hljs-literal">null</span> <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span> <span class="hljs-comment">// false</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x9664;&#x4E86;<code>null</code>&#xFF0C;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x7684;<code>instanceOf Object</code>&#x7684;&#x8FD0;&#x7B97;&#x7ED3;&#x679C;&#x90FD;&#x662F;<code>true</code>&#x3002;</p>
<p><code>instanceof</code>&#x7684;&#x539F;&#x7406;&#x662F;&#x68C0;&#x67E5;&#x53F3;&#x8FB9;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;<code>prototype</code>&#x5C5E;&#x6027;&#xFF0C;&#x662F;&#x5426;&#x5728;&#x5DE6;&#x8FB9;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x94FE;&#x4E0A;&#x3002;&#x6709;&#x4E00;&#x79CD;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#xFF0C;&#x5C31;&#x662F;&#x5DE6;&#x8FB9;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x94FE;&#x4E0A;&#xFF0C;&#x53EA;&#x6709;<code>null</code>&#x5BF9;&#x8C61;&#x3002;&#x8FD9;&#x65F6;&#xFF0C;<code>instanceof</code>&#x5224;&#x65AD;&#x4F1A;&#x5931;&#x771F;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = <span class="hljs-built_in">Object</span>.create(<span class="hljs-literal">null</span>);
<span class="hljs-keyword">typeof</span> obj <span class="hljs-comment">// &quot;object&quot;</span>
<span class="hljs-built_in">Object</span>.create(<span class="hljs-literal">null</span>) <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span> <span class="hljs-comment">// false</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>Object.create(null)</code>&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x5BF9;&#x8C61;<code>obj</code>&#xFF0C;&#x5B83;&#x7684;&#x539F;&#x578B;&#x662F;<code>null</code>&#xFF08;<code>Object.create</code>&#x7684;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#x89C1;&#x540E;&#x6587;&#xFF09;&#x3002;&#x53F3;&#x8FB9;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;<code>Object</code>&#x7684;<code>prototype</code>&#x5C5E;&#x6027;&#xFF0C;&#x4E0D;&#x5728;&#x5DE6;&#x8FB9;&#x7684;&#x539F;&#x578B;&#x94FE;&#x4E0A;&#xFF0C;&#x56E0;&#x6B64;<code>instanceof</code>&#x5C31;&#x8BA4;&#x4E3A;<code>obj</code>&#x4E0D;&#x662F;<code>Object</code>&#x7684;&#x5B9E;&#x4F8B;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x53EA;&#x8981;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x4E0D;&#x662F;<code>null</code>&#xFF0C;<code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x5224;&#x65AD;&#x5C31;&#x4E0D;&#x4F1A;&#x5931;&#x771F;&#x3002;</p>
<p><code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x4E00;&#x4E2A;&#x7528;&#x5904;&#xFF0C;&#x662F;&#x5224;&#x65AD;&#x503C;&#x7684;&#x7C7B;&#x578B;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> x = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
<span class="hljs-keyword">var</span> y = {};
x <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Array</span> <span class="hljs-comment">// true</span>
y <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span> <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#x5224;&#x65AD;&#xFF0C;&#x53D8;&#x91CF;<code>x</code>&#x662F;&#x6570;&#x7EC4;&#xFF0C;&#x53D8;&#x91CF;<code>y</code>&#x662F;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;<code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#x53EA;&#x80FD;&#x7528;&#x4E8E;&#x5BF9;&#x8C61;&#xFF0C;&#x4E0D;&#x9002;&#x7528;&#x539F;&#x59CB;&#x7C7B;&#x578B;&#x7684;&#x503C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> s = <span class="hljs-string">&apos;hello&apos;</span>;
s <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">String</span> <span class="hljs-comment">// false</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5B57;&#x7B26;&#x4E32;&#x4E0D;&#x662F;<code>String</code>&#x5BF9;&#x8C61;&#x7684;&#x5B9E;&#x4F8B;&#xFF08;&#x56E0;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;&#x4E0D;&#x662F;&#x5BF9;&#x8C61;&#xFF09;&#xFF0C;&#x6240;&#x4EE5;&#x8FD4;&#x56DE;<code>false</code>&#x3002;</p>
<p>&#x6B64;&#x5916;&#xFF0C;&#x5BF9;&#x4E8E;<code>undefined</code>&#x548C;<code>null</code>&#xFF0C;<code>instanceOf</code>&#x8FD0;&#x7B97;&#x7B26;&#x603B;&#x662F;&#x8FD4;&#x56DE;<code>false</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-literal">undefined</span> <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span> <span class="hljs-comment">// false</span>
<span class="hljs-literal">null</span> <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span> <span class="hljs-comment">// false</span>
</code></pre>
<p>&#x5229;&#x7528;<code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x5DE7;&#x5999;&#x5730;&#x89E3;&#x51B3;&#xFF0C;&#x8C03;&#x7528;&#x6784;&#x9020;&#x51FD;&#x6570;&#x65F6;&#xFF0C;&#x5FD8;&#x4E86;&#x52A0;<code>new</code>&#x547D;&#x4EE4;&#x7684;&#x95EE;&#x9898;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Fubar</span> (<span class="hljs-params">foo, bar</span>) </span>{
  <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span> <span class="hljs-keyword">instanceof</span> Fubar) {
    <span class="hljs-keyword">this</span>._foo = foo;
    <span class="hljs-keyword">this</span>._bar = bar;
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Fubar(foo, bar);
  }
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4F7F;&#x7528;<code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x5224;&#x65AD;<code>this</code>&#x5173;&#x952E;&#x5B57;&#x662F;&#x5426;&#x4E3A;&#x6784;&#x9020;&#x51FD;&#x6570;<code>Fubar</code>&#x7684;&#x5B9E;&#x4F8B;&#x3002;&#x5982;&#x679C;&#x4E0D;&#x662F;&#xFF0C;&#x5C31;&#x8868;&#x660E;&#x5FD8;&#x4E86;&#x52A0;<code>new</code>&#x547D;&#x4EE4;&#x3002;</p>
<h2 id="&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x7EE7;&#x627F;">&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x7EE7;&#x627F;</h2>
<p>&#x8BA9;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7EE7;&#x627F;&#x53E6;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x662F;&#x975E;&#x5E38;&#x5E38;&#x89C1;&#x7684;&#x9700;&#x6C42;&#x3002;&#x8FD9;&#x53EF;&#x4EE5;&#x5206;&#x6210;&#x4E24;&#x6B65;&#x5B9E;&#x73B0;&#x3002;&#x7B2C;&#x4E00;&#x6B65;&#x662F;&#x5728;&#x5B50;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E2D;&#xFF0C;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Sub</span>(<span class="hljs-params">value</span>) </span>{
  Super.call(<span class="hljs-keyword">this</span>);
  <span class="hljs-keyword">this</span>.prop = value;
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>Sub</code>&#x662F;&#x5B50;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;<code>this</code>&#x662F;&#x5B50;&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#x3002;&#x5728;&#x5B9E;&#x4F8B;&#x4E0A;&#x8C03;&#x7528;&#x7236;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;<code>Super</code>&#xFF0C;&#x5C31;&#x4F1A;&#x8BA9;&#x5B50;&#x7C7B;&#x5B9E;&#x4F8B;&#x5177;&#x6709;&#x7236;&#x7C7B;&#x5B9E;&#x4F8B;&#x7684;&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x7B2C;&#x4E8C;&#x6B65;&#xFF0C;&#x662F;&#x8BA9;&#x5B50;&#x7C7B;&#x7684;&#x539F;&#x578B;&#x6307;&#x5411;&#x7236;&#x7C7B;&#x7684;&#x539F;&#x578B;&#xFF0C;&#x8FD9;&#x6837;&#x5B50;&#x7C7B;&#x5C31;&#x53EF;&#x4EE5;&#x7EE7;&#x627F;&#x7236;&#x7C7B;&#x539F;&#x578B;&#x3002;</p>
<pre><code class="lang-javascript">Sub.prototype = <span class="hljs-built_in">Object</span>.create(Super.prototype);
Sub.prototype.constructor = Sub;
Sub.prototype.method = <span class="hljs-string">&apos;...&apos;</span>;
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>Sub.prototype</code>&#x662F;&#x5B50;&#x7C7B;&#x7684;&#x539F;&#x578B;&#xFF0C;&#x8981;&#x5C06;&#x5B83;&#x8D4B;&#x503C;&#x4E3A;<code>Object.create(Super.prototype)</code>&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x76F4;&#x63A5;&#x7B49;&#x4E8E;<code>Super.prototype</code>&#x3002;&#x5426;&#x5219;&#x540E;&#x9762;&#x4E24;&#x884C;&#x5BF9;<code>Sub.prototype</code>&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x4F1A;&#x8FDE;&#x7236;&#x7C7B;&#x7684;&#x539F;&#x578B;<code>Super.prototype</code>&#x4E00;&#x8D77;&#x4FEE;&#x6539;&#x6389;&#x3002;</p>
<p>&#x53E6;&#x5916;&#x4E00;&#x79CD;&#x5199;&#x6CD5;&#x662F;<code>Sub.prototype</code>&#x7B49;&#x4E8E;&#x4E00;&#x4E2A;&#x7236;&#x7C7B;&#x5B9E;&#x4F8B;&#x3002;</p>
<pre><code class="lang-javascript">Sub.prototype = <span class="hljs-keyword">new</span> Super();
</code></pre>
<p>&#x4E0A;&#x9762;&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x4E5F;&#x6709;&#x7EE7;&#x627F;&#x7684;&#x6548;&#x679C;&#xFF0C;&#x4F46;&#x662F;&#x5B50;&#x7C7B;&#x4F1A;&#x5177;&#x6709;&#x7236;&#x7C7B;&#x5B9E;&#x4F8B;&#x7684;&#x65B9;&#x6CD5;&#x3002;&#x6709;&#x65F6;&#xFF0C;&#x8FD9;&#x53EF;&#x80FD;&#x4E0D;&#x662F;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x63A8;&#x8350;&#x4F7F;&#x7528;&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x3002;</p>
<p>&#x4E3E;&#x4F8B;&#x6765;&#x8BF4;&#xFF0C;&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;<code>Shape</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Shape</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">this</span>.x = <span class="hljs-number">0</span>;
  <span class="hljs-keyword">this</span>.y = <span class="hljs-number">0</span>;
}

Shape.prototype.move = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">x, y</span>) </span>{
  <span class="hljs-keyword">this</span>.x += x;
  <span class="hljs-keyword">this</span>.y += y;
  <span class="hljs-built_in">console</span>.info(<span class="hljs-string">&apos;Shape moved.&apos;</span>);
};
</code></pre>
<p>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x8BA9;<code>Rectangle</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#x7EE7;&#x627F;<code>Shape</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x7B2C;&#x4E00;&#x6B65;&#xFF0C;&#x5B50;&#x7C7B;&#x7EE7;&#x627F;&#x7236;&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Rectangle</span>(<span class="hljs-params"></span>) </span>{
  Shape.call(<span class="hljs-keyword">this</span>); <span class="hljs-comment">// &#x8C03;&#x7528;&#x7236;&#x7C7B;&#x6784;&#x9020;&#x51FD;&#x6570;</span>
}
<span class="hljs-comment">// &#x53E6;&#x4E00;&#x79CD;&#x5199;&#x6CD5;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Rectangle</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">this</span>.base = Shape;
  <span class="hljs-keyword">this</span>.base();
}

<span class="hljs-comment">// &#x7B2C;&#x4E8C;&#x6B65;&#xFF0C;&#x5B50;&#x7C7B;&#x7EE7;&#x627F;&#x7236;&#x7C7B;&#x7684;&#x539F;&#x578B;</span>
Rectangle.prototype = <span class="hljs-built_in">Object</span>.create(Shape.prototype);
Rectangle.prototype.constructor = Rectangle;
</code></pre>
<p>&#x91C7;&#x7528;&#x8FD9;&#x6837;&#x7684;&#x5199;&#x6CD5;&#x4EE5;&#x540E;&#xFF0C;<code>instanceof</code>&#x8FD0;&#x7B97;&#x7B26;&#x4F1A;&#x5BF9;&#x5B50;&#x7C7B;&#x548C;&#x7236;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x90FD;&#x8FD4;&#x56DE;<code>true</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> rect = <span class="hljs-keyword">new</span> Rectangle();

rect <span class="hljs-keyword">instanceof</span> Rectangle  <span class="hljs-comment">// true</span>
rect <span class="hljs-keyword">instanceof</span> Shape  <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5B50;&#x7C7B;&#x662F;&#x6574;&#x4F53;&#x7EE7;&#x627F;&#x7236;&#x7C7B;&#x3002;&#x6709;&#x65F6;&#x53EA;&#x9700;&#x8981;&#x5355;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x7EE7;&#x627F;&#xFF0C;&#x8FD9;&#x65F6;&#x53EF;&#x4EE5;&#x91C7;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x5199;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript">ClassB.prototype.print = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  ClassA.prototype.print.call(<span class="hljs-keyword">this</span>);
  <span class="hljs-comment">// some code</span>
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5B50;&#x7C7B;<code>B</code>&#x7684;<code>print</code>&#x65B9;&#x6CD5;&#x5148;&#x8C03;&#x7528;&#x7236;&#x7C7B;<code>A</code>&#x7684;<code>print</code>&#x65B9;&#x6CD5;&#xFF0C;&#x518D;&#x90E8;&#x7F72;&#x81EA;&#x5DF1;&#x7684;&#x4EE3;&#x7801;&#x3002;&#x8FD9;&#x5C31;&#x7B49;&#x4E8E;&#x7EE7;&#x627F;&#x4E86;&#x7236;&#x7C7B;<code>A</code>&#x7684;<code>print</code>&#x65B9;&#x6CD5;&#x3002;</p>
<h2 id="&#x591A;&#x91CD;&#x7EE7;&#x627F;">&#x591A;&#x91CD;&#x7EE7;&#x627F;</h2>
<p>JavaScript &#x4E0D;&#x63D0;&#x4F9B;&#x591A;&#x91CD;&#x7EE7;&#x627F;&#x529F;&#x80FD;&#xFF0C;&#x5373;&#x4E0D;&#x5141;&#x8BB8;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x540C;&#x65F6;&#x7EE7;&#x627F;&#x591A;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x53D8;&#x901A;&#x65B9;&#x6CD5;&#xFF0C;&#x5B9E;&#x73B0;&#x8FD9;&#x4E2A;&#x529F;&#x80FD;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">M1</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">this</span>.hello = <span class="hljs-string">&apos;hello&apos;</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">M2</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">this</span>.world = <span class="hljs-string">&apos;world&apos;</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">S</span>(<span class="hljs-params"></span>) </span>{
  M1.call(<span class="hljs-keyword">this</span>);
  M2.call(<span class="hljs-keyword">this</span>);
}

<span class="hljs-comment">// &#x7EE7;&#x627F; M1</span>
S.prototype = <span class="hljs-built_in">Object</span>.create(M1.prototype);
<span class="hljs-comment">// &#x7EE7;&#x627F;&#x94FE;&#x4E0A;&#x52A0;&#x5165; M2</span>
<span class="hljs-built_in">Object</span>.assign(S.prototype, M2.prototype);

<span class="hljs-comment">// &#x6307;&#x5B9A;&#x6784;&#x9020;&#x51FD;&#x6570;</span>
S.prototype.constructor = S;

<span class="hljs-keyword">var</span> s = <span class="hljs-keyword">new</span> S();
s.hello <span class="hljs-comment">// &apos;hello&apos;</span>
s.world <span class="hljs-comment">// &apos;world&apos;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5B50;&#x7C7B;<code>S</code>&#x540C;&#x65F6;&#x7EE7;&#x627F;&#x4E86;&#x7236;&#x7C7B;<code>M1</code>&#x548C;<code>M2</code>&#x3002;&#x8FD9;&#x79CD;&#x6A21;&#x5F0F;&#x53C8;&#x79F0;&#x4E3A; Mixin&#xFF08;&#x6DF7;&#x5165;&#xFF09;&#x3002;</p>
<h2 id="&#x6A21;&#x5757;">&#x6A21;&#x5757;</h2>
<p>&#x968F;&#x7740;&#x7F51;&#x7AD9;&#x9010;&#x6E10;&#x53D8;&#x6210;&#x201C;&#x4E92;&#x8054;&#x7F51;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x201D;&#xFF0C;&#x5D4C;&#x5165;&#x7F51;&#x9875;&#x7684; JavaScript &#x4EE3;&#x7801;&#x8D8A;&#x6765;&#x8D8A;&#x5E9E;&#x5927;&#xFF0C;&#x8D8A;&#x6765;&#x8D8A;&#x590D;&#x6742;&#x3002;&#x7F51;&#x9875;&#x8D8A;&#x6765;&#x8D8A;&#x50CF;&#x684C;&#x9762;&#x7A0B;&#x5E8F;&#xFF0C;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x56E2;&#x961F;&#x5206;&#x5DE5;&#x534F;&#x4F5C;&#x3001;&#x8FDB;&#x5EA6;&#x7BA1;&#x7406;&#x3001;&#x5355;&#x5143;&#x6D4B;&#x8BD5;&#x7B49;&#x7B49;&#x2026;&#x2026;&#x5F00;&#x53D1;&#x8005;&#x5FC5;&#x987B;&#x4F7F;&#x7528;&#x8F6F;&#x4EF6;&#x5DE5;&#x7A0B;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x7BA1;&#x7406;&#x7F51;&#x9875;&#x7684;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x3002;</p>
<p>JavaScript &#x6A21;&#x5757;&#x5316;&#x7F16;&#x7A0B;&#xFF0C;&#x5DF2;&#x7ECF;&#x6210;&#x4E3A;&#x4E00;&#x4E2A;&#x8FEB;&#x5207;&#x7684;&#x9700;&#x6C42;&#x3002;&#x7406;&#x60F3;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5F00;&#x53D1;&#x8005;&#x53EA;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x6838;&#x5FC3;&#x7684;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#xFF0C;&#x5176;&#x4ED6;&#x90FD;&#x53EF;&#x4EE5;&#x52A0;&#x8F7D;&#x522B;&#x4EBA;&#x5DF2;&#x7ECF;&#x5199;&#x597D;&#x7684;&#x6A21;&#x5757;&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;JavaScript &#x4E0D;&#x662F;&#x4E00;&#x79CD;&#x6A21;&#x5757;&#x5316;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#xFF0C;ES6 &#x624D;&#x5F00;&#x59CB;&#x652F;&#x6301;&#x201C;&#x7C7B;&#x201D;&#x548C;&#x201C;&#x6A21;&#x5757;&#x201D;&#x3002;&#x4E0B;&#x9762;&#x4ECB;&#x7ECD;&#x4F20;&#x7EDF;&#x7684;&#x505A;&#x6CD5;&#xFF0C;&#x5982;&#x4F55;&#x5229;&#x7528;&#x5BF9;&#x8C61;&#x5B9E;&#x73B0;&#x6A21;&#x5757;&#x7684;&#x6548;&#x679C;&#x3002;</p>
<h3 id="&#x57FA;&#x672C;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x6CD5;">&#x57FA;&#x672C;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x6CD5;</h3>
<p>&#x6A21;&#x5757;&#x662F;&#x5B9E;&#x73B0;&#x7279;&#x5B9A;&#x529F;&#x80FD;&#x7684;&#x4E00;&#x7EC4;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x7684;&#x5C01;&#x88C5;&#x3002;</p>
<p>&#x7B80;&#x5355;&#x7684;&#x505A;&#x6CD5;&#x662F;&#x628A;&#x6A21;&#x5757;&#x5199;&#x6210;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x6240;&#x6709;&#x7684;&#x6A21;&#x5757;&#x6210;&#x5458;&#x90FD;&#x653E;&#x5230;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x91CC;&#x9762;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> module1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>({
&#x3000;_count : <span class="hljs-number">0</span>,
&#x3000;m1 : <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)</span>{
&#x3000;&#x3000;<span class="hljs-comment">//...</span>
&#x3000;},
&#x3000;m2 : <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)</span>{
  &#x3000;<span class="hljs-comment">//...</span>
&#x3000;}
});
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x51FD;&#x6570;<code>m1</code>&#x548C;<code>m2</code>&#xFF0C;&#x90FD;&#x5C01;&#x88C5;&#x5728;<code>module1</code>&#x5BF9;&#x8C61;&#x91CC;&#x3002;&#x4F7F;&#x7528;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5C31;&#x662F;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x3002;</p>
<pre><code class="lang-javascript">module1.m1();
</code></pre>
<p>&#x4F46;&#x662F;&#xFF0C;&#x8FD9;&#x6837;&#x7684;&#x5199;&#x6CD5;&#x4F1A;&#x66B4;&#x9732;&#x6240;&#x6709;&#x6A21;&#x5757;&#x6210;&#x5458;&#xFF0C;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x53EF;&#x4EE5;&#x88AB;&#x5916;&#x90E8;&#x6539;&#x5199;&#x3002;&#x6BD4;&#x5982;&#xFF0C;&#x5916;&#x90E8;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x6539;&#x53D8;&#x5185;&#x90E8;&#x8BA1;&#x6570;&#x5668;&#x7684;&#x503C;&#x3002;</p>
<pre><code class="lang-javascript">module1._count = <span class="hljs-number">5</span>;
</code></pre>
<h3 id="&#x5C01;&#x88C5;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#xFF1A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x5199;&#x6CD5;">&#x5C01;&#x88C5;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#xFF1A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x5199;&#x6CD5;</h3>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5229;&#x7528;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x5C01;&#x88C5;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">StringBuilder</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> buffer = [];

  <span class="hljs-keyword">this</span>.add = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">str</span>) </span>{
     buffer.push(str);
  };

  <span class="hljs-keyword">this</span>.toString = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> buffer.join(<span class="hljs-string">&apos;&apos;</span>);
  };

}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>buffer</code>&#x662F;&#x6A21;&#x5757;&#x7684;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x3002;&#x4E00;&#x65E6;&#x751F;&#x6210;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x5916;&#x90E8;&#x662F;&#x65E0;&#x6CD5;&#x76F4;&#x63A5;&#x8BBF;&#x95EE;<code>buffer</code>&#x7684;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x5C06;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x5C01;&#x88C5;&#x5728;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E2D;&#xFF0C;&#x5BFC;&#x81F4;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E0E;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x662F;&#x4E00;&#x4F53;&#x7684;&#xFF0C;&#x603B;&#x662F;&#x5B58;&#x5728;&#x4E8E;&#x5185;&#x5B58;&#x4E4B;&#x4E2D;&#xFF0C;&#x65E0;&#x6CD5;&#x5728;&#x4F7F;&#x7528;&#x5B8C;&#x6210;&#x540E;&#x6E05;&#x9664;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#xFF0C;&#x6784;&#x9020;&#x51FD;&#x6570;&#x6709;&#x53CC;&#x91CD;&#x4F5C;&#x7528;&#xFF0C;&#x65E2;&#x7528;&#x6765;&#x5851;&#x9020;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x53C8;&#x7528;&#x6765;&#x4FDD;&#x5B58;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x8FDD;&#x80CC;&#x4E86;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E0E;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x5728;&#x6570;&#x636E;&#x4E0A;&#x76F8;&#x5206;&#x79BB;&#x7684;&#x539F;&#x5219;&#xFF08;&#x5373;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x4E0D;&#x5E94;&#x8BE5;&#x4FDD;&#x5B58;&#x5728;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x4EE5;&#x5916;&#xFF09;&#x3002;&#x540C;&#x65F6;&#xFF0C;&#x975E;&#x5E38;&#x8017;&#x8D39;&#x5185;&#x5B58;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">StringBuilder</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">this</span>._buffer = [];
}

StringBuilder.prototype = {
  <span class="hljs-keyword">constructor</span>: StringBuilder,
  add: function (str) {
    <span class="hljs-keyword">this</span>._buffer.push(str);
  },
  toString: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._buffer.join(<span class="hljs-string">&apos;&apos;</span>);
  }
};
</code></pre>
<p>&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x5C06;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x653E;&#x5165;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x4E2D;&#xFF0C;&#x597D;&#x5904;&#x662F;&#x770B;&#x4E0A;&#x53BB;&#x66F4;&#x81EA;&#x7136;&#xFF0C;&#x4F46;&#x662F;&#x5B83;&#x7684;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x53EF;&#x4EE5;&#x4ECE;&#x5916;&#x90E8;&#x8BFB;&#x5199;&#xFF0C;&#x4E0D;&#x662F;&#x5F88;&#x5B89;&#x5168;&#x3002;</p>
<h3 id="&#x5C01;&#x88C5;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#xFF1A;&#x7ACB;&#x5373;&#x6267;&#x884C;&#x51FD;&#x6570;&#x7684;&#x5199;&#x6CD5;">&#x5C01;&#x88C5;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#xFF1A;&#x7ACB;&#x5373;&#x6267;&#x884C;&#x51FD;&#x6570;&#x7684;&#x5199;&#x6CD5;</h3>
<p>&#x53E6;&#x4E00;&#x79CD;&#x505A;&#x6CD5;&#x662F;&#x4F7F;&#x7528;&#x201C;&#x7ACB;&#x5373;&#x6267;&#x884C;&#x51FD;&#x6570;&#x201D;&#xFF08;Immediately-Invoked Function Expression&#xFF0C;IIFE&#xFF09;&#xFF0C;&#x5C06;&#x76F8;&#x5173;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x5C01;&#x88C5;&#x5728;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x91CC;&#x9762;&#xFF0C;&#x53EF;&#x4EE5;&#x8FBE;&#x5230;&#x4E0D;&#x66B4;&#x9732;&#x79C1;&#x6709;&#x6210;&#x5458;&#x7684;&#x76EE;&#x7684;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> module1 = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
&#x3000;<span class="hljs-keyword">var</span> _count = <span class="hljs-number">0</span>;
&#x3000;<span class="hljs-keyword">var</span> m1 = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
&#x3000;  <span class="hljs-comment">//...</span>
&#x3000;};
&#x3000;<span class="hljs-keyword">var</span> m2 = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
&#x3000;&#x3000;<span class="hljs-comment">//...</span>
&#x3000;};
&#x3000;<span class="hljs-keyword">return</span> {
&#x3000;&#x3000;m1 : m1,
&#x3000;&#x3000;m2 : m2
&#x3000;};
})();
</code></pre>
<p>&#x4F7F;&#x7528;&#x4E0A;&#x9762;&#x7684;&#x5199;&#x6CD5;&#xFF0C;&#x5916;&#x90E8;&#x4EE3;&#x7801;&#x65E0;&#x6CD5;&#x8BFB;&#x53D6;&#x5185;&#x90E8;&#x7684;<code>_count</code>&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.info(module1._count); <span class="hljs-comment">//undefined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;<code>module1</code>&#x5C31;&#x662F; JavaScript &#x6A21;&#x5757;&#x7684;&#x57FA;&#x672C;&#x5199;&#x6CD5;&#x3002;&#x4E0B;&#x9762;&#xFF0C;&#x518D;&#x5BF9;&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x8FDB;&#x884C;&#x52A0;&#x5DE5;&#x3002;</p>
<h3 id="&#x6A21;&#x5757;&#x7684;&#x653E;&#x5927;&#x6A21;&#x5F0F;">&#x6A21;&#x5757;&#x7684;&#x653E;&#x5927;&#x6A21;&#x5F0F;</h3>
<p>&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5F88;&#x5927;&#xFF0C;&#x5FC5;&#x987B;&#x5206;&#x6210;&#x51E0;&#x4E2A;&#x90E8;&#x5206;&#xFF0C;&#x6216;&#x8005;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x9700;&#x8981;&#x7EE7;&#x627F;&#x53E6;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x8FD9;&#x65F6;&#x5C31;&#x6709;&#x5FC5;&#x8981;&#x91C7;&#x7528;&#x201C;&#x653E;&#x5927;&#x6A21;&#x5F0F;&#x201D;&#xFF08;augmentation&#xFF09;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> module1 = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">mod</span>)</span>{
&#x3000;mod.m3 = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
&#x3000;&#x3000;<span class="hljs-comment">//...</span>
&#x3000;};
&#x3000;<span class="hljs-keyword">return</span> mod;
})(module1);
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x4E3A;<code>module1</code>&#x6A21;&#x5757;&#x6DFB;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x65B0;&#x65B9;&#x6CD5;<code>m3()</code>&#xFF0C;&#x7136;&#x540E;&#x8FD4;&#x56DE;&#x65B0;&#x7684;<code>module1</code>&#x6A21;&#x5757;&#x3002;</p>
<p>&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x73AF;&#x5883;&#x4E2D;&#xFF0C;&#x6A21;&#x5757;&#x7684;&#x5404;&#x4E2A;&#x90E8;&#x5206;&#x901A;&#x5E38;&#x90FD;&#x662F;&#x4ECE;&#x7F51;&#x4E0A;&#x83B7;&#x53D6;&#x7684;&#xFF0C;&#x6709;&#x65F6;&#x65E0;&#x6CD5;&#x77E5;&#x9053;&#x54EA;&#x4E2A;&#x90E8;&#x5206;&#x4F1A;&#x5148;&#x52A0;&#x8F7D;&#x3002;&#x5982;&#x679C;&#x91C7;&#x7528;&#x4E0A;&#x9762;&#x7684;&#x5199;&#x6CD5;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x6267;&#x884C;&#x7684;&#x90E8;&#x5206;&#x6709;&#x53EF;&#x80FD;&#x52A0;&#x8F7D;&#x4E00;&#x4E2A;&#x4E0D;&#x5B58;&#x5728;&#x7A7A;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD9;&#x65F6;&#x5C31;&#x8981;&#x91C7;&#x7528;&quot;&#x5BBD;&#x653E;&#x5927;&#x6A21;&#x5F0F;&quot;&#xFF08;Loose augmentation&#xFF09;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> module1 = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">mod</span>) </span>{
&#x3000;<span class="hljs-comment">//...</span>
&#x3000;<span class="hljs-keyword">return</span> mod;
})(<span class="hljs-built_in">window</span>.module1 || {});
</code></pre>
<p>&#x4E0E;&quot;&#x653E;&#x5927;&#x6A21;&#x5F0F;&quot;&#x76F8;&#x6BD4;&#xFF0C;&#x201C;&#x5BBD;&#x653E;&#x5927;&#x6A21;&#x5F0F;&#x201D;&#x5C31;&#x662F;&#x201C;&#x7ACB;&#x5373;&#x6267;&#x884C;&#x51FD;&#x6570;&#x201D;&#x7684;&#x53C2;&#x6570;&#x53EF;&#x4EE5;&#x662F;&#x7A7A;&#x5BF9;&#x8C61;&#x3002;</p>
<h3 id="&#x8F93;&#x5165;&#x5168;&#x5C40;&#x53D8;&#x91CF;">&#x8F93;&#x5165;&#x5168;&#x5C40;&#x53D8;&#x91CF;</h3>
<p>&#x72EC;&#x7ACB;&#x6027;&#x662F;&#x6A21;&#x5757;&#x7684;&#x91CD;&#x8981;&#x7279;&#x70B9;&#xFF0C;&#x6A21;&#x5757;&#x5185;&#x90E8;&#x6700;&#x597D;&#x4E0D;&#x4E0E;&#x7A0B;&#x5E8F;&#x7684;&#x5176;&#x4ED6;&#x90E8;&#x5206;&#x76F4;&#x63A5;&#x4EA4;&#x4E92;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x5728;&#x6A21;&#x5757;&#x5185;&#x90E8;&#x8C03;&#x7528;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF0C;&#x5FC5;&#x987B;&#x663E;&#x5F0F;&#x5730;&#x5C06;&#x5176;&#x4ED6;&#x53D8;&#x91CF;&#x8F93;&#x5165;&#x6A21;&#x5757;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> module1 = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">$, YAHOO</span>) </span>{
&#x3000;<span class="hljs-comment">//...</span>
})(jQuery, YAHOO);
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;<code>module1</code>&#x6A21;&#x5757;&#x9700;&#x8981;&#x4F7F;&#x7528; jQuery &#x5E93;&#x548C; YUI &#x5E93;&#xFF0C;&#x5C31;&#x628A;&#x8FD9;&#x4E24;&#x4E2A;&#x5E93;&#xFF08;&#x5176;&#x5B9E;&#x662F;&#x4E24;&#x4E2A;&#x6A21;&#x5757;&#xFF09;&#x5F53;&#x4F5C;&#x53C2;&#x6570;&#x8F93;&#x5165;<code>module1</code>&#x3002;&#x8FD9;&#x6837;&#x505A;&#x9664;&#x4E86;&#x4FDD;&#x8BC1;&#x6A21;&#x5757;&#x7684;&#x72EC;&#x7ACB;&#x6027;&#xFF0C;&#x8FD8;&#x4F7F;&#x5F97;&#x6A21;&#x5757;&#x4E4B;&#x95F4;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x53D8;&#x5F97;&#x660E;&#x663E;&#x3002;</p>
<p>&#x7ACB;&#x5373;&#x6267;&#x884C;&#x51FD;&#x6570;&#x8FD8;&#x53EF;&#x4EE5;&#x8D77;&#x5230;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x4F5C;&#x7528;&#x3002;</p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">$, window, document</span>) </span>{

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">go</span>(<span class="hljs-params">num</span>) </span>{
  }

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleEvents</span>(<span class="hljs-params"></span>) </span>{
  }

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">initialize</span>(<span class="hljs-params"></span>) </span>{
  }

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">dieCarouselDie</span>(<span class="hljs-params"></span>) </span>{
  }

  <span class="hljs-comment">//attach to the global scope</span>
  <span class="hljs-built_in">window</span>.finalCarousel = {
    init : initialize,
    destroy : dieCarouselDie
  }

})( jQuery, <span class="hljs-built_in">window</span>, <span class="hljs-built_in">document</span> );
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>finalCarousel</code>&#x5BF9;&#x8C61;&#x8F93;&#x51FA;&#x5230;&#x5168;&#x5C40;&#xFF0C;&#x5BF9;&#x5916;&#x66B4;&#x9732;<code>init</code>&#x548C;<code>destroy</code>&#x63A5;&#x53E3;&#xFF0C;&#x5185;&#x90E8;&#x65B9;&#x6CD5;<code>go</code>&#x3001;<code>handleEvents</code>&#x3001;<code>initialize</code>&#x3001;<code>dieCarouselDie</code>&#x90FD;&#x662F;&#x5916;&#x90E8;&#x65E0;&#x6CD5;&#x8C03;&#x7528;&#x7684;&#x3002;</p>
<h2 id="&#x53C2;&#x8003;&#x94FE;&#x63A5;">&#x53C2;&#x8003;&#x94FE;&#x63A5;</h2>
<ul>
<li><a href="https://medium.freecodecamp.com/javascript-modules-a-beginner-s-guide-783f7d7a5fcc" target="_blank" rel="nofollow">JavaScript Modules: A Beginner&#x2019;s Guide</a>, by Preethi Kasireddy</li>
</ul>




<footer class="page-footer-ex"> <span class="page-footer-ex-copyright"> <a href="https://xiaobaiai.net" target="_blank" rel="nofollow">&#x5C0F;&#x767D;AI.&#x6613;&#x540D;</a>, &#x4F7F;&#x7528;<a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="nofollow">&#x77E5;&#x8BC6;&#x5171;&#x4EAB; 4.0 &#x534F;&#x8BAE;&#x53D1;&#x5E03;</a>&#x53D1;&#x5E03; </span> &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0; <span class="page-footer-ex-footer-update"> <i>&#x9875;&#x9762;&#x4FEE;&#x8BA2;&#x4E8E;&#xFF1A;</i> 2019-08-22 16:53:02 </span> </footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="this.html" class="navigation navigation-prev " aria-label="Previous page: this 关键字">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="object.html" class="navigation navigation-next " aria-label="Next page: Object 对象的相关方法">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"对象的继承","level":"1.7.3","depth":2,"next":{"title":"Object 对象的相关方法","level":"1.7.4","depth":2,"path":"docs/oop/object.md","ref":"docs/oop/object.md","articles":[]},"previous":{"title":"this 关键字","level":"1.7.2","depth":2,"path":"docs/oop/this.md","ref":"docs/oop/this.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","chapter-fold","back-to-top-button","search-pro","sharing-plus","myseo","favicon","page-footer-ex","search-pro","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"livereload":{},"page-footer-ex":{"copyright":"<a href='https://xiaobaiai.net' target='_blank'>小白AI.易名</a>, 使用<a href='https://creativecommons.org/licenses/by-sa/4.0/' target='_blank'>知识共享 4.0 协议发布</a>发布","markdown":false,"update_format":"YYYY-MM-DD HH:mm:ss","update_label":"<i>页面修订于：</i>"},"search-pro":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"myseo":{"description":"Javascript教程","keywords":"小白AI.易名,xiaobaiai.net,Javascript,入门,教程,博客","titlePrefix":"Javascript教程 - ","titleSuffix":" - 小白AI.易名"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico","appleTouch":"assets/images/apple-touch-icon.png","appleTouchMore":{"120x120":"assets/images/apple-touch-icon-120x120.png","180x180":"assets/images/apple-touch-icon-180x180.png"}},"back-to-top-button":{},"sharing":{"qq":true,"all":["qq","qzone","twitter","weibo","linkedin"],"douban":false,"facebook":true,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"小白AI.易名","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"zh-hans","gitbook":"*","description":"Javascript教程"},"file":{"path":"docs/oop/prototype.md","mtime":"2019-08-22T08:53:02.356Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-08-28T05:00:46.673Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

